#!/bin/bash
source /data/miniconda3/etc/profile.d/conda.sh
conda activate yyd

source /data/daily/set_env.sh
# math仓依赖算子编译
if [ -d "/data/daily/ops-math-dev" ]; then
        rm -rf /data/daily/ops-math-dev
fi
git clone https://cc-z:BuAsNKVC7jsaHB1UsSFhBnMx@gitcode.com/cann/ops-math-dev.git /data/daily/ops-math-dev
cd /data/daily/ops-math-dev || exit
bash build.sh --pkg --ops=is_finite,masked_select_v3
bash build_out/cann-ops-math-custom_linux-aarch64.run --install-path=/data/daily/custom/math

# nn仓编译
if [ -d "/data/daily/ops-nn-dev" ]; then
        rm -rf /data/daily/ops-nn-dev
fi
git clone https://cc-z:BuAsNKVC7jsaHB1UsSFhBnMx@gitcode.com/cann/ops-nn-dev.git /data/daily/ops-nn-dev
cd /data/daily/ops-nn-dev || exit
rm -f /data/daily/Ascend/latest/opp/built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/aarch64/libopmaster_rt2.0.so
bash build.sh --pkg --ops=ascend_quant_v2,inplace_index_add_with_sorted,cross_entropy_loss,cross_entropy_loss_grad,group_norm_silu,group_norm_swish,group_norm_swish_grad
bash build_out/cann-ops-nn-custom-linux.aarch64.run --install-path=/data/daily/custom/nn

# transformer仓编译
if [ -d "/data/daily/ops-transformer-dev" ]; then
    rm -rf /data/daily/ops-transformer-dev
fi
git clone https://cc-z:BuAsNKVC7jsaHB1UsSFhBnMx@gitcode.com/cann/ops-transformer-dev.git /data/daily/ops-transformer-dev
cd /data/daily/ops-transformer-dev || exit

bash build.sh --pkg --ops=dequant_rope_quant_kvcache,grouped_matmul,grouped_matmul_add,grouped_matmul_swiglu_quant,moe_compute_expert_tokens,moe_finalize_routing,moe_finalize_routing_v2,moe_finalize_routing_v2_grad,moe_gating_top_k_softmax,moe_gating_top_k_softmax_v2,moe_init_routing,moe_init_routing_quant,moe_init_routing_quant_v2,moe_init_routing_v2,moe_init_routing_v2_grad,moe_token_permute,moe_token_permute_grad,moe_token_permute_with_ep,moe_token_permute_with_ep_grad,moe_token_permute_with_routing_map,moe_token_permute_with_routing_map_grad,moe_token_unpermute,moe_token_unpermute_grad,moe_token_unpermute_with_ep,moe_token_unpermute_with_ep_grad,moe_token_unpermute_with_routing_map,moe_token_unpermute_with_routing_map_grad,rope_with_sin_cos_cache
bash build_out/cann-ops-transformer-custom_linux-aarch64.run --install-path=/data/daily/custom/transformer

# 环境变量
source /data/daily/custom/transformer/vendors/custom_transformer/bin/set_env.bash
source /data/daily/custom/nn/vendors/custom_nn/bin/set_env.bash
source /data/daily/custom/math/vendors/custom_math/bin/set_env.bash

# 执行
cd /data/daily/gmm-atk-samples
rm -rf atk_output/
bash run_atk.sh -m daily -r custom